﻿using System.Web.UI.WebControls;
using System.Web.UI;
using System.ComponentModel;
using SiteUnity.Layers.Application;
using SiteUnity.Layers.Application.BaseClasses;

namespace SiteUnity.Frame.Modules
{
    [ToolboxData("<{0}:PageHeader runat=server/>")]
    public class PageHeader : BaseWebControl
    {
        public HtmlTextWriterTag HtmlTag { get; set; }
        public bool AutoHideInHome { get; set; }
        public string Text { get; set; }

        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);

            if (string.IsNullOrEmpty(Text))
                Text = SiteManager.Website.CurrentPage.Title;
        }

        protected override void RenderContents(HtmlTextWriter output)
        {
            if (AutoHideInHome)
                if (SiteManager.Website.Pages.Count != 0 && SiteManager.Website.Pages[0] == SiteManager.Website.CurrentPage)
                    return;

            output.RenderBeginTag(HtmlTag);
            output.Write(Text);
            output.RenderEndTag();
        }
    }
}
